var app = getApp();
Page({
  data: {
  	info:null,
  	opens:0,
  	sex:["男","女"],//性别
  	sexindex:0,
  },
  onLoad(options) {
  	var info=wx.getStorageSync('userInfo')
  	var $th=this;
		$th.setData({
  		info:info,
  		sexindex:Number(info.gender)
    });
    console.log(info)
  },
  setopens:function(){//弹出
  	var $th=this;
  	var o=$th.data.opens?0:1;
		$th.setData({
  		opens:o
    });
  },
  selectsex:function(e){//选择
  	var $th=this,
  			cur=e.currentTarget.dataset;
				$th.setData({
		  		sexindex:Number(cur.index)
		    });
		    $th.setopens();
  },
  formSubmit:function(e){
  	console.log(e.detail.value)
 
  	var that=this;
  	var post=e.detail.value
  	if(post.nickname==""){
  		wx.showToast({
        title: "昵称不能为空",
        icon: "none"});
  		return false;
  	}
  	if(post.realName==""){
  		wx.showToast({
        title: "用户名不能为空",
        icon: "none"});
  		return false;
  	}
  	if(post.mobile==""){
  		wx.showToast({
        title: "手机号不能为空",
        icon: "none"});
  		return false;
  	}
  	
  	var info=wx.getStorageSync('userInfo')
				info.realName=post.realName
				info.gender=post.gender
				info.mobile=post.mobile
				
  	app.globalAjax(
	  		'/api/member/update',
	  		"post",
	  		post,
	  		function(e){
	  			if(e.code==0)
	      	{
	      		wx.showToast({
						    title: '修改成功',
						    icon: 'none',
						    duration: 2000,
						    success: function () {
						    	setTimeout(function(){
						    		var pages = getCurrentPages(); // 获取页面栈
										var currPage = pages[pages.length - 1]; // 当前页面
										var prevPage = pages[pages.length - 2]; // 上一个页面
										wx.setStorage({
										   key: "userInfo",
										   data: info //需要存储的数据
										})
										prevPage.gengxin();
										wx.navigateBack({delta: 1})
						    	},2000)
						    }
						});
	      	}else{
	      		wx.showToast({
				        title: e.msg,
				        icon: "none"
				      });
	      	}
	  	})
  },inp:function(e){//监听输入
  	var that=this;
  	
  }
})